package com.moli.iov.handle.alarm.biz.valid.alarm;

import com.moli.iov.handle.alarm.biz.valid.ValidHandler;
import com.moli.iov.handle.alarm.biz.utils.AlarmUtils;
import com.moli.iov.handle.alarm.model.dto.AlarmDto;
import com.moli.iov.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 忽略报警拦截
 * </p>
 *
 * @author zql
 * @since 2019/9/3 10:53
 */
@Slf4j
@Component
public class IgnoreValidHandler  implements ValidHandler<AlarmDto> {

  @Autowired
  private AlarmUtils alarmUtils;

  @Override
  public boolean doHandle(AlarmDto alarmDto) {

    if(isIgnoreAlarm(alarmDto.getVin(), alarmDto.getAlarmCode())){
      log.info("报警 已忽略告警 vin:{} alarmCode:{}",
          alarmDto.getVin(), alarmDto.getAlarmCode());
      return false;
    }

    return true;
  }

  /**
   * 判断是否已忽略告警
   * @param vin
   * @param alarmCode
   * @return
   */
  private boolean isIgnoreAlarm(String vin, Integer alarmCode){
    String obj = alarmUtils.getIgnoreAlarm(vin, alarmCode);

    return StringUtil.isNotBlank(obj);
  }
}
